package com.xxcxcxcx.xc_crop.common.inits;

import com.google.common.base.Supplier;
import com.xxcxcxcx.xc_crop.common.blocks.crops.minecraft.TreeSaplingBlock.*;
import com.xxcxcxcx.xc_crop.common.blocks.crops.minecraft.melon.*;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.grower.*;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.material.MaterialColor;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;

import java.util.function.Function;

public class BlockInit {
    public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, "minecraft");
    public static final DeferredRegister<Item> ITEMS = ItemInit.ITEMS;
    public static final RegistryObject<Block> OAK_SAPLING = BLOCKS.register("oak_sapling", () -> new OakSaplingBlock(new OakTreeGrower(), BlockBehaviour.Properties.of(Material.PLANT).noCollission().randomTicks().instabreak().sound(SoundType.GRASS)));
    public static final RegistryObject<Block> SPRUCE_SAPLING = BLOCKS.register("spruce_sapling", () -> new SpruceSaplingBlock(new SpruceTreeGrower(), BlockBehaviour.Properties.of(Material.PLANT).noCollission().randomTicks().instabreak().sound(SoundType.GRASS)));
    public static final RegistryObject<Block> BIRCH_SAPLING = BLOCKS.register("birch_sapling", () -> new BirchSaplingBlock(new BirchTreeGrower(), BlockBehaviour.Properties.of(Material.PLANT).noCollission().randomTicks().instabreak().sound(SoundType.GRASS)));
    public static final RegistryObject<Block> JUNGLE_SAPLING = BLOCKS.register("jungle_sapling", () -> new JungleSaplingBlock(new JungleTreeGrower(), BlockBehaviour.Properties.of(Material.PLANT).noCollission().randomTicks().instabreak().sound(SoundType.GRASS)));
    public static final RegistryObject<Block> ACACIA_SAPLING = BLOCKS.register("acacia_sapling", () -> new AcaciaSaplingBlock(new AcaciaTreeGrower(), BlockBehaviour.Properties.of(Material.PLANT).noCollission().randomTicks().instabreak().sound(SoundType.GRASS)));
    public static final RegistryObject<Block> DARK_OAK_SAPLING = BLOCKS.register("dark_oak_sapling", () -> new DarkOakSaplingBlock(new DarkOakTreeGrower(), BlockBehaviour.Properties.of(Material.PLANT).noCollission().randomTicks().instabreak().sound(SoundType.GRASS)));
    public static final RegistryObject<Block> POTTED_OAK_SAPLING = BLOCKS.register("potted_oak_sapling", () ->new FlowerPotBlock(OAK_SAPLING.get(), BlockBehaviour.Properties.of(Material.DECORATION).instabreak().noOcclusion()));
    public static final RegistryObject<Block> POTTED_SPRUCE_SAPLING = BLOCKS.register("potted_spruce_sapling", () -> new FlowerPotBlock(SPRUCE_SAPLING.get(), BlockBehaviour.Properties.of(Material.DECORATION).instabreak().noOcclusion()));
    public static final RegistryObject<Block> POTTED_BIRCH_SAPLING = BLOCKS.register("potted_birch_sapling", () -> new FlowerPotBlock(BIRCH_SAPLING.get(), BlockBehaviour.Properties.of(Material.DECORATION).instabreak().noOcclusion()));
    public static final RegistryObject<Block> POTTED_JUNGLE_SAPLING = BLOCKS.register("potted_jungle_sapling", () -> new FlowerPotBlock(JUNGLE_SAPLING.get(), BlockBehaviour.Properties.of(Material.DECORATION).instabreak().noOcclusion()));
    public static final RegistryObject<Block> POTTED_ACACIA_SAPLING = BLOCKS.register("potted_acacia_sapling", () -> new FlowerPotBlock(ACACIA_SAPLING.get(), BlockBehaviour.Properties.of(Material.DECORATION).instabreak().noOcclusion()));
    public static final RegistryObject<Block> POTTED_DARK_OAK_SAPLING = BLOCKS.register("potted_dark_oak_sapling", () -> new FlowerPotBlock(DARK_OAK_SAPLING.get(), BlockBehaviour.Properties.of(Material.DECORATION).instabreak().noOcclusion()));
    public static final RegistryObject<Block> PUMPKIN = BLOCKS.register("pumpkin", () -> new PumpkinBlockChange(BlockBehaviour.Properties.of(Material.VEGETABLE, MaterialColor.COLOR_ORANGE).strength(1.0F).sound(SoundType.WOOD)));
    public static final RegistryObject<Block> MELON = BLOCKS.register("melon", () -> new MelonBlockChange(BlockBehaviour.Properties.of(Material.VEGETABLE, MaterialColor.COLOR_LIGHT_GREEN).strength(1.0F).sound(SoundType.WOOD)));
    public static final RegistryObject<Block> ATTACHED_PUMPKIN_STEM = BLOCKS.register("attached_pumpkin_stem", () -> new PumpkinAttachedStemBlockChange((StemGrownBlock)PUMPKIN.get(), () -> {
        return ItemInit.PUMPKIN_SEEDS.get();
    }, BlockBehaviour.Properties.of(Material.PLANT).noCollission().instabreak().sound(SoundType.WOOD)));
    public static final RegistryObject<Block> ATTACHED_MELON_STEM = BLOCKS.register("attached_melon_stem", () -> new MelonAttachedStemBlockChange((StemGrownBlock)MELON.get(), () -> {
        return ItemInit.MELON_SEEDS.get();
    }, BlockBehaviour.Properties.of(Material.PLANT).noCollission().instabreak().sound(SoundType.WOOD)));
    public static final RegistryObject<Block> PUMPKIN_STEM = BLOCKS.register("pumpkin_stem", () -> new PumpkinStemBlockChange((StemGrownBlock)PUMPKIN.get(), () -> {
        return ItemInit.PUMPKIN_SEEDS.get();
    }, BlockBehaviour.Properties.of(Material.PLANT).noCollission().randomTicks().instabreak().sound(SoundType.HARD_CROP)));
    public static final RegistryObject<Block> MELON_STEM = BLOCKS.register("melon_stem", () -> new MelonStemBlockChange((StemGrownBlock)MELON.get(), () -> {
        return ItemInit.MELON_SEEDS.get();
    }, BlockBehaviour.Properties.of(Material.PLANT).noCollission().randomTicks().instabreak().sound(SoundType.HARD_CROP)));
    private static <T extends Block> RegistryObject<T> registerBlock(final String name, final Supplier<? extends T> block) {
        return BLOCKS.register(name, block);
    }
    private static <T extends Block> RegistryObject<T> register(final String name, final Supplier<? extends T> block, Function<RegistryObject<T>, Supplier<? extends Item>> item) {
        RegistryObject<T> obj = registerBlock(name, block);
        ITEMS.register(name, item.apply(obj));
        return obj;
    }
}
